package com.crdeng.business.controller;


import com.crdeng.business.service.ProductCategoryService;
import com.crdeng.business.vo.PageVO;
import com.crdeng.business.vo.ProductCategoryVO;
import com.crdeng.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 产品分类
 * </p>
 *
 * @author crdeng
 * @since 2020-12-19
 */
@Api(value = "物资分类", tags = "物资分类模块")
@RestController
@RequestMapping("/productCategory")
public class ProductCategoryController {


    @Autowired
    private ProductCategoryService productCategoryService;

    @ApiOperation(value = "分类树", notes = "")
    @GetMapping("/getProductCategoryTree")
    public Result getProductCategoryTree(@RequestParam(value = "pageNum", required = false) Integer pageNum,
                                         @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        PageVO<ProductCategoryVO> productCategoryTree = productCategoryService.getProductCategoryTree(pageNum, pageSize);
        return Result.ok().data("list", productCategoryTree);
    }


    @ApiOperation(value = "二级分层树",notes = "获取分层到2层")
    @GetMapping("/getProductCategory2Tree")
    public  Result getProductCategory2Tree(){
        List<ProductCategoryVO> productCategory2Tree = productCategoryService.getProductCategory2Tree();
        return Result.ok().data("tree2List",productCategory2Tree);
    }


    @ApiOperation(value = "编辑分类", notes = "")
    @PutMapping("/edit")
    public Result edit(@RequestBody ProductCategoryVO productCategoryVO) {
        System.out.println(productCategoryVO);
        productCategoryService.edit(productCategoryVO);
         return Result.ok();
    }

    @ApiOperation(value = "删除分类", notes = "")
    @DeleteMapping("/delete")
    public Result delete(@RequestParam Long id) {

        productCategoryService.delete(id);
         return Result.ok();
    }


    @ApiOperation(value = "添加分层")
    @PostMapping("/add")
    public Result add(@RequestBody ProductCategoryVO productCategoryVO ){
        productCategoryService.add(productCategoryVO);
        return  Result.ok().message("添加成功");
    }
}

